package com.hedl.practice.diyJava.io.study_file.practice;

import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;

public class Main {
    public static void main(String[] args) throws IOException {
        File currentDir = new File("/Users/a101/idea");
        listDir(currentDir.getCanonicalFile());
    }

    static void listDir(File dir) {
        // TODO: 递归打印所有文件和子文件夹的内容
        File[] fs = dir.listFiles();
        String a = "        ";
        int s = 1;
        if (fs != null) {
            for (File f : fs) {
                if (f.isDirectory()){
                    System.out.println(a+f.getName()+"--目录"+s);
                    listDir(f);
                }
                if (f.isFile()){
                    System.out.println(f.getName()+"文件"+s++);
                }
            }
        }
    }
}
